package com.bizuma.spring.ws.template;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bizuma.template.domain.Person;
import com.bizuma.template.provider.PersonProvider;

@Controller
// @RequestMapping("/owners/{ownerId}/**")
public class PersonController {

	// /**
	// * http://www.example.com/psersons/fred
	// *
	// * @return
	// */
	// @RequestMapping(value = "/psersons/{personId}", method =
	// RequestMethod.GET)
	// public String getPerson(@PathVariable String userId, Model model) {
	// Person person = new Person();
	// person.setFirstName("bg");
	// person.setLastName("kang");
	// person.setId(Integer.valueOf(userId));
	// model.addAttribute("person", person);
	// return "";
	// }

	// @RequestMapping(value = "/something", method = RequestMethod.PUT)
	// public void handle(@RequestBody String body, Writer writer)
	// throws IOException {
	// writer.write(body);
	// }

	@RequestMapping(method = RequestMethod.GET, value = "/psersons/{personId}")
	public @ResponseBody
	Person getPerson(@PathVariable String personId) {
		Person person = new Person();
		person.setFirstName("bg");
		person.setLastName("kang");
		person.setId(Integer.valueOf(personId));
		return person;
	}
	
	@Autowired
	private PersonProvider personProvider;
	
	@RequestMapping(method = RequestMethod.POST, value = "/pserson/register")
	public @ResponseBody
	Person registerPerson(@RequestBody  Person person) {
		this.personProvider.registerPerson(person);
//		Person person = new Person();
//		person.setFirstName("bg");
//		person.setLastName("kang");
//		person.setId(Integer.valueOf(personId));
		return person;
	}
}
